Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
' Global variables.
Public Const rmConfigure = 1
Public Const rmScreenSaver = 2
Public Const rmPreview = 3
Public RunMode As Integer
Public Type Ball
BallClr As Long
BallR As Single
BallX As Single
BallY As Single
BallVx As Single
BallVy As Single
End Type
Public NumBalls As Integer
Public Balls() As Ball
' Private variables.
Private Const APP_NAME = "BouncingBalls"
' See if another instance of the program is
' running in screen saver mode.
Private Sub CheckShouldRun()
' If no instance is running, we're safe.
If Not App.PrevInstance Then Exit Sub
' See if there is a screen saver mode instance.
If FindWindow(vbNullString, APP_NAME) Then End
' Set our caption so other instances can find
' us in the previous line.
frmCover.Caption = APP_NAME
End Sub
' Load configuration information from the registry.
Public Sub LoadConfig()
NumBalls = CInt(GetSetting(APP_NAME, _
"Settings", "NumBalls", "1"))
End Sub
' Initialize the balls.
Public Sub InitializeBalls()
Const MIN_CLR = 1
Const MAX_CLR = 15
Const MIN_BALLR = 0.03 ' Fraction of screen width.